<?php
require_once('config.php');
require_once('mysqlii.php');

$db = MySqlii::getInstance();

$tableName = "down_log";
$tableDate = date("Ym", time() - 3600*24);
$tableName .= $tableDate;

$date = date("Y-m-d", time() - 3600*24); 
//$date = '2014-12-15';
$sql = "select count(*) as res_count,channel_id from $tableName where date = '$date' group by channel_id";
//echo $sql;
$res = $db->query($sql);
$data = array();
$row = $res->fetch_array();
/**/
while ($row) {
	$data[] = $row;
	$row = $res->fetch_array();
}

//echo "<pre>";
//print_r($data);
//exit();

foreach ($data as $value) {
	$channel_id = $value['channel_id'];
	$res_count = $value['res_count'];
	$upsql = "update t_client_channel set res_count = $res_count where date_sk = '$date' and channelid = $channel_id";
	$res = $db->query($upsql);
	var_dump($upsql);
	var_dump($res);
}
exit();
?>
